﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace KGE.Define
{
    [Serializable]
    public class KMovie
    {
        [Serializable]
        public class Frame
        {
            public double Length;
            public Color FilterColor;
            public Rectangle DrawRectangle;
            public KImage KImage;
            public KSound KSound;

            public Frame()
            {
                //KSound = new KSound();
                //KImage = new KImage();
            }
        }

        public string Name;
        public Guid GUID;
        public string Version;
        public DateTime CreateTime;

        public List<Frame> Frames = new List<Frame>();
        public double Length
        {
            get
            {
                double l = 0.0;
                foreach (Frame f in Frames)
                {
                    l += f.Length;
                }
                return l;
            }
        }
        public Size Size
        {
            get
            {
                int w = 0;
                int h = 0;
                foreach (Frame f in Frames)
                {
                    if (f.DrawRectangle.Width > w)
                    {
                        w = f.DrawRectangle.Width;
                    }
                    if (f.DrawRectangle.Height > h)
                    {
                        h = f.DrawRectangle.Height;
                    }
                }
                return new Size(w, h);
            }
        }


        public KMovie()
        {
            GUID = Guid.NewGuid();
            CreateTime = DateTime.Now;
        }


        [NonSerialized]
        int frameIndex = -1;
        public void FrameIncrease()
        {
            frameIndex++;
        }
        public double LastUpdateTime = 0.0;
        public Frame CurrentFrame
        {
            get
            {
                return Frames[frameIndex % Frames.Count];
            }
        }
    }
}
